#ifndef  SL_DRAW_STATE_GRAPH_H_
#define  SL_DRAW_STATE_GRAPH_H_
#include "Config.h"
#include "ref_ptr.h"
#include "Referenced.h"
#include "DrawAtrributeSet.h"
#include "StateLeaf.h"
namespace sl
{

	class RenderInfo;
	struct LessDepthSortFunctor
	{
		bool operator () ( const sl::ref_ptr<StateLeaf> &lhs, const sl::ref_ptr<StateLeaf> &rhs )
		{
			return (lhs->m_fDepth < rhs->m_fDepth );
		}
	};

	class SL_EXPORT StateGraph : public Referenced
	{
	public:

		enum eSortType
		{
			DEPTH = 0,
		};

		typedef std::map< const sl::DrawAttributeSet *, sl::ref_ptr<StateGraph> >	GraphChildList;
		typedef std::vector< sl::ref_ptr< sl::StateLeaf >>					StateLeafList;	
		StateGraph(void){};
		~StateGraph(void) {};

		inline void AddStateLeaf( sl::StateLeaf * pStateLeaf )
		{
			if ( pStateLeaf )
			{
				m_vStateLeafList.push_back( pStateLeaf );
			}
		}

		inline void SortFontToBack()
		{
			std::sort( m_vStateLeafList.begin(), m_vStateLeafList.end(), LessDepthSortFunctor() );
		}

		inline void SortStateGraph(eSortType type = DEPTH )
		{
			// base on the type of type 
			switch ( type )
			{
				case DEPTH:
					SortFontToBack();
					break;
				default:
					break;
			}
		}


		void Reset();

		void Clean();

		void Draw( sl::RenderInfo * pRenderInfo );

	protected:

		StateLeafList			m_vStateLeafList;
		GraphChildList			m_vGraphChildList;
	};
}

#endif

